import { login } from '@/api/user'
import { getToken, setToken } from '@/utils/auth'
const state = {
  token: getToken(),   // 共享token
  userInfo: {},   // 保存用户信息
}
const mutations = {
  setToken(state, token) {
    // console.log("token:", token);
    state.token = token;   // 修改token
    // 同步进行缓存token
    setToken(token);
  }
}
const actions = {
  async login({commit}, data) {
    // console.log("data:", data);
    const result = await login(data);
    // console.log("result:", result);
    commit('setToken', result.data);    // 进行设置tolen
  }
}

export default {
  namespaced: true,
  state,
  mutations,
  actions
}
